package com.apes.hr.base.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.frame.model.Branch;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：员工编制
 * @author HuJianlin
 * @create 2018-04-25 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = Staffing.CONST_TABLE_NAME)
public class Staffing extends Model {
    public static final String CONST_TABLE_NAME = "hr_staffing";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "员工编制")
    private String id;   //员工编制编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    private PartyRole company; //所属公司

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "branch_id", referencedColumnName = "id")
    private Branch branch; //工作部门-行政部门

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "work_post_id", referencedColumnName = "id")
    private WorkPost workPost; //职位

    @Name
    @Column(name = "plan_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int planQty = 0;  //定编人数

    @Name
    @Column(name = "real_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int realQty = 0;  //正式员工人数

    @Name
    @Column(name = "probation_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int probationQty = 0;  //试用人数

    public int calcQty() {
        return realQty + probationQty;
    }

    @Name
    @Column(name = "practice_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int practiceQty = 0;  //实习人数

    @Name
    @Column(name = "leave_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int leaveQty = 0;  //将离职人数

    @Name
    @Column(name = "recruit_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int recruitQty = 0;  //申请招聘人数

    @Name
    @Column(name = "apply_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int applyQty = 0;  //应聘人数

    @Name
    @Column(name = "stop_recruit_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int stopRecruitQty = 0;  //暂停招聘人数

    @Name
    @Column(name = "delay_qty",nullable = false,columnDefinition = "number(8,0) default 0")
    private int delayQty = 0;//待入职人数

    @Name
    @Column(name = "transfer_in_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int transferInQty = 0;  //将调入人数

    @Name
    @Column(name = "transfer_out_qty", nullable = false, columnDefinition = "number(8,0) default 0")
    private int transferOutQty = 0;  //将调出人数

    @Column(name = "DESCRIPTION", length = 500)
    private String description; //说明

}
